<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>党员个人先锋指数</title>
<%@ include file="/module/js.jsp"%>

<script>
			$(document).ready(function() {
				var _form=$("#Form").validate();
				/* 保存  */
				 $("#btnSave").click(function() {
						if(_form.form()){ 
						   document.Form.action ="${basePath}/dyxfzs/insert";
							document.Form.submit();
					 }  
				});
				/* 返回 */
				$("#returnBut").click(function() {
		 			   window.location.href='${basePath}/dyxfzs/list';
		 		});
				/*  取消 */
				$("#Cancel").click(function() {
					   window.location.href = "${basePath}/dyxfzs/preadd";
		 		});
			});
			
			   if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			  } 
		</script>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input type="hidden" name="dYID" id="dYID" />
		 <input type="hidden" id="score" name="score"/>
		 <input type="hidden" id="ItemNum" name="ItemNum" value="${ItemNum}"/>
		<table cellpadding="1" cellspacing="1" style="width: 60%;">
			<tr>
				<td style="width: 15%">评定学期：</td>
				<td style="width: auto;">
					<select id="semId" name="semId" class="selectList2">
						<option value="">全部</option>
						<c:forEach items="${semesterList}" var="semester">
							<option value="${semester.xqid}">${semester.xqmc}</option>
						</c:forEach>
					</select>
					<script>
                        compareListValue(document.getElementById("semId"),'${semester.xqid}');
					</script>
				</td>
			</tr>
			<tr>
				<td style="width: 15%">党支部：</td>
				<td style="width: 30%"><select id="dZBID" name="dZBID"
					class="selectList2">
						<option value="">全部</option>
						<c:forEach items="${pList}" var="data">
							<option value="${data.zBID}">${data.dZBMC}</option>
						</c:forEach>
				</select></td>
				<td style="width: 15%">姓名：</td>
				<td style="width: 30%"><input type="text" name="xM" id="xM" autocomplete="off"
					class="inputText" /></td>
				<td><input type="button" id="btnQuery" value="查询"
					class="inputButton" /></td>
			</tr>
		</table>
		<table id="dg">

		</table>
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<c:if test="${_login_user_type==2}">
			<tr>
				<td>
				<kl:permission permisstionList="${permisstionList}"
               currentUser="${_login_console_user}"
               currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_KHGL_XFZS\")%>" key="add">
				<input type="button" id="btnSave" class="inputButton"
					style="text-align: center;" value="保存" />
				</kl:permission>	
				</td>
				<td><input type="button" id="Cancel" class="inputButton"
					style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton"
					value="返回" style="text-align: center;" /></td>
			</tr>
	     </c:if>
		</table>
	</form>
	<script>
	  //格式化部门名称
	  function dYID(val,row,index) {
		  return row.dYID;
	  }
	  
	    function xM(val,row,index){
			 return row.xM;
		} 
    function xB(val,row,index) {
    	return row.xB;
    }
	 function dZBID(val,row,index){
		 return row.partyBranch.dZBMC;	
	 }
	 function itemName(val,row,index) {
	    return row.itemName;  
	 }
    function itemScore(val,row,index){
		return row.itemScore;
	} 
   
    function formatDate(value){
    	var date=new Date(value);
		var y = date.getFullYear();
		var m = date.getMonth()+ 1;
		var d = date.getDate();
		var h= date.getHours();       //获取当前小时数(0-23)
		var mm= date.getMinutes();     //获取当前分钟数(0-59)
		var s= date.getSeconds();     //获取当前秒数(0-59)
		return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+' :'+(h <10?('0'+ h):h)+':'+(mm <10?('0'+ mm):mm)+':'+(s <10?('0'+ s):s);
	}
    
     </script>
	<script type="text/javascript">
	 function isNum(index) {
		 var score = $('#scores'+index).val();
		 var itemScore = $('#itemScore'+index).val();
		 if(!(score <= itemScore)) {
			 layer.alert("您输入的分数不在范围内或不合法,请重新输入",{icon: 3});
			 $('#scores'+index).val("");
		 }
     }
			$(document).ready(function() {
                //加载表格分页数据
                $('#dg').datagrid({
                    url:'${basePath}/dyxfzs/getDyScoreListData',
                    pagination:true,
                    collapsible:true,
                    method:'post',
                    remoteSort:true,
                    queryParams: {
                        semId: $("#semId").val()
                    },
                    pageList:[${ItemNum*10}],
                    singleSelect:true, 
                    columns:[[
                        {field:'dYID',title:'序号',nowrap:true,width:100,align:'center'},
                        {field:'xM',title:'姓名',nowrap:true,width:100,align:'center'},
                        {field:'xB',title:'性别',nowrap:true,width:80,align:'center'},
                        {field:'dZBMC',title:'所在党支部',nowrap:true,width:200,align:'center'},  
                        {field:'itemName',title:'项目',nowrap:true,width:250,align:'center'},
                        {field:'itemScore',title:'分值',nowrap:true,width:100,align:'center'},
                        {field:'score',title:'得分',nowrap:true,width:200,align:'center',formatter:formatInput}
                    ]],
                    onLoadSuccess: onLoadSuccess  
                });

					//查询
				$('#btnQuery').click(function() {
					$('#dg').datagrid('load',{
						dZBID: $('#dZBID').val(),
						dYLB: $('#dYLB').val(),
						dJZT: $('#dJZT').val(),
						xB: $('#xB').val(),
						mZ: $('#mZ').val(),
						wHCD: $('#wHCD').val(),
						isStu: $('#isStu').val(),
						xM: $('#xM').val(),
						semId :$('#semId').val(),
					});
				});
				 if("${msg}"!=""){
				       layer.alert("${msg}", {icon: 6});
				 } 
				 
			});
			 
			function formatInput(value, row, index){
			    var currentScore='';
			    if(row.score!=null && row.score!=''){
                    currentScore = row.score;
				}
				return '<input type="hidden" name="dZBID['+index+']" value="'+row.dZBID+'"/>' +
						'<input type="hidden" name="dyIds['+index+']" value="'+row.dYID+'"/>' +
                    '<input type="hidden" name="items['+index+']" value="'+row.itemId+'"/>' +
                    '<input type="hidden" id="itemScore'+index+'" name="itemScore['+index+']" value="'+row.itemScore+'"/>' +
					'<input type="number" id="scores'+index+'" name="scores['+index+']" value="'+currentScore+'" onBlur="isNum('+index+')"/>';
			}
			function onLoadSuccess(data){
				 var merges=[];
				 var itemNum = ${ItemNum};
				 for (var i = 0; i < data.rows.length; i++) {
					 if(i%itemNum==0){
						 merges.push({index:i,rowspan: itemNum});
					 }
				 }
				 for(var i=0; i<merges.length; i++){
	                $(this).datagrid('mergeCells',{
	                    index: merges[i].index,
	                    field: 'xM',
	                    rowspan: merges[i].rowspan
	                });
	                $(this).datagrid('mergeCells',{
	                    index: merges[i].index,
	                    field: 'xB',
	                    rowspan: merges[i].rowspan
	                });
	                $(this).datagrid('mergeCells',{
	                    index: merges[i].index,
	                    field: 'dZBID',
	                    rowspan: merges[i].rowspan
	                });
	                $(this).datagrid('mergeCells',{
	                    index: merges[i].index,
	                    field: 'dZBMC',
	                    rowspan: merges[i].rowspan
	                });
	                $(this).datagrid('mergeCells',{
	                    index: merges[i].index,
	                    field: 'dYID',
	                    rowspan: merges[i].rowspan
	                });
		        }
	        }
			
	</script>
</body>
</html>
